package com.squirrel.michale;

import java.util.HashSet;

/**
 * @author guanhao 观浩
 * @version 1.0.0.0
 * @createTime 2023/3/1 7:53 AM
 * @company Michale Squirrel
 * @link
 * @description
 */
public class FindElements {
    HashSet<Integer> nodeSet = new HashSet<>();
    public FindElements(TreeNode root) {
        if (root != null) {
            root.val = 0;
            nodeSet.add(root.val);
            dsf(root);
        }
    }

    public boolean find(int target) {
        return nodeSet.contains(target);
    }

    private void dsf(TreeNode node) {
        if (node.left != null) {
            node.left.val = 2 * node.val + 1;
            nodeSet.add(node.left.val);
            dsf(node.left);
        }

        if (node.right != null) {
            node.right.val = 2 * node.val + 2;
            nodeSet.add(node.right.val);
            dsf(node.right);
        }
    }


    public static void main(String[] args) {
        TreeNode root = new TreeNode(-1, null, new TreeNode(-1, null, null));
        FindElements findElements = new FindElements(root);
        System.out.println(findElements.find(2));
    }
}
